home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / d_prompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  6.0 KB  |  250 lines

  1. /*
  2.  * Prompt for directory entry changes.  Copies the original values in
  3.  * case you change your mind half way thru.  A non-zero return code means
  4.  * the entry was changed.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9. #include "config.h"
  10. #include "dial_dir.h"
  11. #include "misc.h"
  12.  
  13. int
  14. prompt_lib(win, i)
  15. WINDOW *win;
  16. int i;
  17. {
  18.     extern int xmc;
  19.     extern char *null_ptr;
  20.     int n, baud, dbits, sbits, spot;
  21.     static int valid_baud[6] = {300, 1200, 2400, 4800, 9600, 19200};
  22.     static char *valid_parity[3] = {"Even", "Odd", "None"};
  23.     char *ans, *get_str(), c, temp, name[40], number[40], script[40];
  24.     char parity, duplex, *str_rep(), *strcpy(), buf[40];
  25.     void free_ptr();
  26.                     /* make copies */
  27.     strcpy(name, dir->name[i]);
  28.     strcpy(number, dir->number[i]);
  29.     baud = dir->baud[i];
  30.     parity = dir->parity[i];
  31.     dbits = dir->dbits[i];
  32.     sbits = dir->sbits[i];
  33.     duplex = dir->duplex[i];
  34.     strcpy(script, dir->script[i]);
  35.                     /* display original values */
  36.     werase(win);
  37.     mvwprintw(win, 2, 5, "%-20.20s %18.18s  %5d-%c-%d-%d  %c  %-14.14s\n",
  38.      dir->name[i], dir->number[i], dir->baud[i], dir->parity[i],
  39.      dir->dbits[i], dir->sbits[i], dir->duplex[i], dir->script[i]);
  40.     box(win, VERT, HORZ);
  41.  
  42.                     /* prompt for name */
  43.     mvwaddstr(win, 4, 4, "Name: ");
  44.     wrefresh(win);
  45.  
  46.     if ((ans = get_str(win, 20, "", ";\n")) == NULL)
  47.         return(0);
  48.     if (*ans != '\0') {
  49.         strcpy(name, ans);
  50.         mvwaddstr(win, 2, 5, "                    ");
  51.         wrefresh(win);
  52.         mvwattrstr(win, 2, 5, A_BOLD, name);
  53.     }
  54.                     /* prompt for number */
  55.     clear_line(win, 4, 4, TRUE);
  56.     waddstr(win, "Number: ");
  57.     wrefresh(win);
  58.  
  59.     if ((ans = get_str(win, 18, "", ";\n")) == NULL)
  60.         return(0);
  61.     if (*ans != '\0') {
  62.         strcpy(number, ans);
  63.         mvwaddstr(win, 2, 26, "                  ");
  64.         wrefresh(win);
  65.         /*
  66.          * Should be right justified, but we don't wanna have
  67.          * the attribute turned on for blanks.
  68.          */
  69.         spot = 26 + 18 - strlen(number);
  70.         mvwattrstr(win, 2, spot, A_BOLD, number);
  71.     }
  72.                     /* template for next few */
  73.     clear_line(win, 4, 4, TRUE);
  74.     mvwaddstr(win, 4, 31, "(Any key to change, <CR> to accept)");
  75.  
  76.     /*
  77.      * These next few prompts display a series of choices and allow
  78.      * the user to hit <CR> to accept the currently showing value
  79.      * or any other key to see the next choice.  The first value
  80.      * displayed is always the current value.
  81.      */
  82.                     /* choose from baud menu */
  83.     for (n=0; n<6; n++) {
  84.         if (valid_baud[n] == baud)
  85.             break;
  86.     }
  87.     mvwprintw(win, 4, 4, "Baud: %-5d", valid_baud[n]);
  88.     wmove(win, 4, 10);
  89.     wrefresh(win);
  90.  
  91.     while ((c = wgetch(win)) != '\r') {
  92.         if (c == ESC)
  93.             return(0);
  94.         n = (n == 5) ? 0 : n+1;
  95.         mvwprintw(win, 4, 4, "Baud: %-5d", valid_baud[n]);
  96.         wmove(win, 4, 10);
  97.         wrefresh(win);
  98.     }
  99.     if (baud != valid_baud[n]) {
  100.         baud = valid_baud[n];
  101.         sprintf(buf, "%5d", baud);
  102.         if (xmc > 0) {
  103.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  104.             mvwaddstr(win, 2, 46, "           ");
  105.             wrefresh(win);
  106.         }
  107.         mvwattrstr(win, 2, 46, A_BOLD, buf);
  108.     }
  109.                     /* choose from parity menu */
  110.     for (n=0; n<3; n++) {
  111.         if (*valid_parity[n] == parity)
  112.             break;
  113.     }
  114.     mvwprintw(win, 4, 4, "Parity: %-5.5s", valid_parity[n]);
  115.     wmove(win, 4, 12);
  116.     wrefresh(win);
  117.  
  118.     while ((c = wgetch(win)) != '\r') {
  119.         if (c == ESC)
  120.             return(0);
  121.         n = (n == 2) ? 0 : n+1;
  122.         mvwprintw(win, 4, 4, "Parity: %-5.5s", valid_parity[n]);
  123.         wmove(win, 4, 12);
  124.         wrefresh(win);
  125.     }
  126.     if (parity != *valid_parity[n]) {
  127.         parity = *valid_parity[n];
  128.         if (xmc > 0) {
  129.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  130.             mvwaddstr(win, 2, 46, "           ");
  131.             wrefresh(win);
  132.             mvwattrstr(win, 2, 46, A_BOLD, buf);
  133.         }
  134.         else
  135.             mvwattrch(win, 2, 52, A_BOLD, parity);
  136.     }
  137.                     /* choose from data bits menu */
  138.     n = dbits;
  139.     mvwprintw(win, 4, 4, "Data Bits: %d    ", n);
  140.     wmove(win, 4, 15);
  141.     wrefresh(win);
  142.  
  143.     while ((c = wgetch(win)) != '\r') {
  144.         if (c == ESC)
  145.             return(0);
  146.         n = (n == 8) ? 7 : 8;
  147.         mvwprintw(win, 4, 4, "Data Bits: %d    ", n);
  148.         wmove(win, 4, 15);
  149.         wrefresh(win);
  150.     }
  151.     if (dbits != n) {
  152.         dbits = n;
  153.         if (xmc > 0) {
  154.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  155.             mvwaddstr(win, 2, 46, "           ");
  156.             wrefresh(win);
  157.             mvwattrstr(win, 2, 46, A_BOLD, buf);
  158.         }
  159.         else
  160.             mvwattrnum(win, 2, 54, A_BOLD, dbits);
  161.     }
  162.                     /* choose from stop bits menu */
  163.     n = sbits;
  164.     mvwprintw(win, 4, 4, "Stop Bits: %d    ", n);
  165.     wmove(win, 4, 15);
  166.     wrefresh(win);
  167.  
  168.     while ((c = wgetch(win)) != '\r') {
  169.         if (c == ESC)
  170.             return(0);
  171.         n = (n == 2) ? 1 : 2;
  172.         mvwprintw(win, 4, 4, "Stop Bits: %d    ", n);
  173.         wmove(win, 4, 15);
  174.         wrefresh(win);
  175.     }
  176.     if (sbits != n) {
  177.         sbits = n;
  178.         if (xmc > 0) {
  179.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  180.             mvwaddstr(win, 2, 46, "           ");
  181.             wrefresh(win);
  182.             mvwattrstr(win, 2, 46, A_BOLD, buf);
  183.         }
  184.         else
  185.             mvwattrnum(win, 2, 56, A_BOLD, sbits);
  186.     }
  187.                     /* choose from duplex menu */
  188.     temp = duplex;
  189.     mvwprintw(win, 4, 4, "Duplex: %c    ", temp);
  190.     wmove(win, 4, 12);
  191.     wrefresh(win);
  192.  
  193.     while ((c = wgetch(win)) != '\r') {
  194.         if (c == ESC)
  195.             return(0);
  196.         temp = (temp == 'F') ? 'H' : 'F';
  197.         mvwprintw(win, 4, 4, "Duplex: %c    ", temp);
  198.         wmove(win, 4, 12);
  199.         wrefresh(win);
  200.     }
  201.     if (duplex != temp) {
  202.         duplex = temp;
  203.         mvwattrch(win, 2, 59, A_BOLD, duplex);
  204.     }
  205.                     /* prompt for script or TTY */
  206.     clear_line(win, 4, 4, TRUE);
  207.     waddstr(win, "Script name (or TTY): ");
  208.     wrefresh(win);
  209.  
  210.     if ((ans = get_str(win, 14, "", ";\n")) == NULL)
  211.         return(0);
  212.  
  213.     if (*ans != '\0') {
  214.         strcpy(script, ans);
  215.         mvwaddstr(win, 2, 62, "              ");
  216.         wrefresh(win);
  217.         mvwattrstr(win, 2, 62, A_BOLD, script);
  218.     }
  219.                     /* store 'em for real */
  220.  
  221.     if (!strcmp(name, " ")) {
  222.         free_ptr(dir->name[i]);
  223.         dir->name[i] = null_ptr;
  224.     }
  225.     else
  226.         dir->name[i] = str_rep(dir->name[i], name);
  227.  
  228.     if (!strcmp(number, " ")) {
  229.         free_ptr(dir->number[i]);
  230.         dir->number[i] = null_ptr;
  231.     }
  232.     else
  233.         dir->number[i] = str_rep(dir->number[i], number);
  234.  
  235.     dir->baud[i] = baud;
  236.     dir->parity[i] = parity;
  237.     dir->dbits[i] = dbits;
  238.     dir->sbits[i] = sbits;
  239.     dir->duplex[i] = duplex;
  240.  
  241.     if (!strcmp(script, " ")) {
  242.         free_ptr(dir->script[i]);
  243.         dir->script[i] = null_ptr;
  244.     }
  245.     else
  246.         dir->script[i] = str_rep(dir->script[i], script);
  247.  
  248.     return(1);
  249. }
  250.